//
//  BZCureOneVC.m
//  QuickCure
//
//  Created by brice Mac on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kBtnFrame CGRectMake(0, 0, kScreenW-40, kScreenW/375*40)

#import "BZCureOneVC.h"
#import "BZCureTwoVC.h"
#import "NetWorkDefine.h"
#import "BZCureDataModel.h"
#import "FocusDoctorViewController.h"
#import "BZClickView.h"
#import "BZChooseView.h"
#import "BZCureModel.h"


@interface BZCureOneVC ()

@property(strong,nonatomic)BZCureDataModel *dataModel;
@property(strong,nonatomic)BZCureDataModel *dataModel1;

@property(weak,nonatomic)UIView *jumpV;
@property(weak,nonatomic)UIView *illnessV;
@property(weak,nonatomic)UILabel *illLabel;
@property(weak,nonatomic)UILabel *bingFaLabel;
@property(weak,nonatomic)UILabel *cureLabel;
@property(weak,nonatomic)UIView *bingFaV;

@end

@implementation BZCureOneVC
/*
 //#疾病细分接口----------------------------------------
 // 肿瘤     ci1_id = 1
 // 心血管   ci1_id = 2
 // 神经科   ci1_id = 3
 // 血液科   ci1_id = 4
 // 骨科     ci1_id = 5
 // 公益活动  ci1_id = 6
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupOriginalUI];
    
    //加载细分
    [BZCureDataModel infoListWithCI1_id:self.ci1_id Success:^(BZCureDataModel *dataModel) {
        self.dataModel = dataModel;
    } error:^{
        NSLog(@"网络延时");
    }];
    
    
    //加载并发
    NSDictionary *paramDic1 = @{@"page":@1,@"page_size":@15,@"ci2_id":@3
                                };
    [BZCureDataModel infoListWithUrlString:kComplicationListUrl param:paramDic1 success:^(BZCureDataModel *datamodel1) {
        
        self.dataModel1 = datamodel1;
        
    } error:^{
        NSLog(@"网络延时");
    }];
}


#pragma mark
#pragma mark - 搭建UI界面，添加事件
- (void)setupOriginalUI {
    // 背景颜色
    self.view.backgroundColor = [UIColor colorWithRed:0.902 green:0.902 blue:0.902 alpha:1.0];
    self.title = self.illName;
    
    
    NSInteger radiu = kScreenW/375*40;
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW-60, radiu-5)];
    label1.center = CGPointMake(kScreenW/2, radiu-5);
    label1.text = [NSString stringWithFormat:@"用户信息：抠脚大汉 itcast"];
    [self.view addSubview:label1];
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW-60, radiu-5)];
    label2.center = CGPointMake(kScreenW/2, 2*radiu-10);
    label2.text = [NSString stringWithFormat:@"疾病类型：%@",self.illName];
    [self.view addSubview:label2];
    
    
    //选择疾病细分
    UIView *illnessV = [[UIView alloc]initWithFrame:kBtnFrame];
    illnessV.center = CGPointMake(kScreenW/2, 3*radiu);
    illnessV.tag = 1;
    _illnessV = illnessV;
    UILabel *illLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, illnessV.bounds.size.width/3*2, radiu)];
    illLabel.text = @"请选择疾病细分";
    illLabel.textColor = [UIColor lightGrayColor];
    _illLabel = illLabel;
    [illnessV addSubview:illLabel];
    
    UIImageView *imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    [illnessV addSubview:imgV];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.trailing.mas_equalTo(illnessV).offset(-20);
        make.centerY.mas_equalTo(illnessV);
    }];
    
    UIView *lineV = [[UIView alloc]init];
    lineV.backgroundColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1.0];
    [illnessV addSubview:lineV];
    
    [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(@1);
        make.trailing.mas_equalTo(illnessV).offset(-illnessV.bounds.size.height);
        make.top.mas_equalTo(illnessV).offset(10);
        make.bottom.mas_equalTo(illnessV).offset(-10);
    }];
    
    [self.view addSubview:illnessV];
    illnessV.layer.cornerRadius = 3;
    illnessV.layer.masksToBounds = YES;
    illnessV.backgroundColor = [UIColor whiteColor];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [illnessV addGestureRecognizer:tap1];
    
    
    //选择并发症(可多选)
    UIView *bingFaV = [[UIView alloc]initWithFrame:kBtnFrame];
    bingFaV.center = CGPointMake(kScreenW/2, 4.4*radiu);
    bingFaV.tag = 2;
    _bingFaV = bingFaV;
    UILabel *bingFaLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, bingFaV.bounds.size.width/3*2, radiu)];
    _bingFaLabel = bingFaLabel;
    bingFaLabel.text = @"请选择并发症（可多选）";
    bingFaLabel.textColor = [UIColor lightGrayColor];
    [bingFaV addSubview:bingFaLabel];
    
    UIImageView *img2V = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    [bingFaV addSubview:img2V];
    [img2V mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.trailing.mas_equalTo(bingFaV).offset(-20);
        make.centerY.mas_equalTo(bingFaV);
    }];
    
    UIView *line2V = [[UIView alloc]init];
    line2V.backgroundColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1.0];
    [bingFaV addSubview:line2V];
    
    [line2V mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(@1);
        make.trailing.mas_equalTo(bingFaV).offset(-bingFaV.bounds.size.height);
        make.top.mas_equalTo(bingFaV).offset(10);
        make.bottom.mas_equalTo(bingFaV).offset(-10);
    }];
    
    [self.view addSubview:bingFaV];
    bingFaV.layer.cornerRadius = 3;
    bingFaV.layer.masksToBounds = YES;
    bingFaV.backgroundColor = [UIColor whiteColor];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [bingFaV addGestureRecognizer:tap2];
    
    //选择是否确诊
    BZClickView *choseView3 = [[BZClickView alloc]initWithFrame:kBtnFrame];
    
    [self.view addSubview:choseView3];
    choseView3.layer.cornerRadius = 3;
    choseView3.layer.masksToBounds = YES;
    choseView3.center = CGPointMake(kScreenW/2, 5.8*radiu);
    
    
    //选择治疗方式
    BZChooseView *choseView4 = [[BZChooseView alloc]initWithFrame:kBtnFrame];
    
    [self.view addSubview:choseView4];
    choseView4.layer.cornerRadius = 3;
    choseView4.layer.masksToBounds = YES;
    choseView4.center = CGPointMake(kScreenW/2, 7.2*radiu);
    
    
    //治疗方式
    UIView *cureType = [[UIView alloc]initWithFrame:kBtnFrame];
    cureType.tag = 3;
    UILabel *cureLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, cureType.bounds.size.width/3*2, radiu)];
    _cureLabel = cureLabel;
    cureLabel.text = @"请选择治疗方式";
    cureLabel.textColor = [UIColor lightGrayColor];
    [cureType addSubview:cureLabel];
    
    UIImageView *img3V = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    [cureType addSubview:img3V];
    [img3V mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.trailing.mas_equalTo(cureType).offset(-20);
        make.centerY.mas_equalTo(cureType);
    }];
    
    UIView *line3V = [[UIView alloc]init];
    line3V.backgroundColor = [UIColor colorWithRed:0.502 green:0.502 blue:0.502 alpha:1.0];
    [cureType addSubview:line3V];
    
    [line3V mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(@1);
        make.trailing.mas_equalTo(cureType).offset(-cureType.bounds.size.height);
        make.top.mas_equalTo(cureType).offset(10);
        make.bottom.mas_equalTo(cureType).offset(-10);
    }];
    
    cureType.backgroundColor= [UIColor whiteColor];
    [self.view addSubview:cureType];
    cureType.layer.cornerRadius = 3;
    cureType.layer.masksToBounds = YES;
    cureType.center = CGPointMake(kScreenW/2, 8.6*radiu);
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [cureType addGestureRecognizer:tap4];
    //创建出来就隐藏
    cureType.hidden = YES;
    
    choseView4.block = ^(BOOL isHidden){
        
        cureType.hidden = !isHidden;
    };
    
    
    //就医申请
    UIButton *cureButton = [[UIButton alloc]init];
    [self.view addSubview:cureButton];
    cureButton.layer.cornerRadius = 3;
    cureButton.layer.masksToBounds = YES;
    
    [cureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(20);
        make.trailing.mas_equalTo(self.view).offset(-20);
        make.bottom.mas_equalTo(self.view).offset(-20);
        make.height.mas_equalTo(@40);
    }];
    
    [cureButton setBackgroundColor:[UIColor colorWithRed:0.0575 green:0.8428 blue:0.4626 alpha:1.0]];
    [cureButton setTitle:@"就医申请" forState:UIControlStateNormal];
    
    [cureButton addTarget:self action:@selector(cureBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    //图片
    UIImageView *iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    [self.view addSubview:iconImgV];
    
    //底部约束
    iconImgV.layer.cornerRadius = radiu;
    iconImgV.layer.masksToBounds = YES;
    
    [iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(cureButton.mas_top).offset(-(radiu/2));
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(@(2*radiu));
        make.height.mas_equalTo(@(2*radiu));
    }];
    
    UILabel *matchLabel = [[UILabel alloc]init];
    [self.view addSubview:matchLabel];
    matchLabel.text = @"为您匹配到: 42位医生";
    matchLabel.font = [UIFont systemFontOfSize:18];
    matchLabel.textAlignment = NSTextAlignmentCenter;
    
    [matchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(iconImgV.mas_top).offset(-(radiu/4));
        make.leading.mas_equalTo(self.view).offset(@(radiu));
        make.trailing.mas_equalTo(self.view).offset(@(-radiu));
        make.height.mas_equalTo(@(radiu));
    }];
}

- (void)tap:(UITapGestureRecognizer *)tap {
    
    UIView *tapV = tap.view;
    NSInteger tagV = tapV.tag;
    
    BZCureTwoVC *tapVC = [[BZCureTwoVC alloc]init];
    
    if (tagV == 1) {
        tapVC.listArray = self.dataModel.data;
        // 回调的给illLabel赋值的block
        tapVC.dataBlock = ^(NSString *returnString){
            
            self.illLabel.textColor = [UIColor blackColor];
            self.illLabel.text = returnString;
        };
        
        UITextField *textField =[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 180, 28)];
        textField.borderStyle = UITextBorderStyleRoundedRect;
        textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 3, 20)];
        textField.leftViewMode = UITextFieldViewModeAlways;
        textField.placeholder = @" 输入关键字";
        textField.font = [UIFont fontWithName:@"Arial" size:15.0f];
        textField.clearButtonMode = UITextFieldViewModeAlways;
        textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        textField.autocorrectionType = UITextAutocorrectionTypeNo;
        
        textField.delegate = tapVC;
        tapVC.searchBar = textField;
        textField.backgroundColor = [UIColor whiteColor];
        tapVC.navigationItem.titleView = textField;
        [textField becomeFirstResponder];
    }
    else if (tagV == 2){
        
        NSMutableArray *pinArr = [NSMutableArray array];
        
        for (int i = 0; i < 4; i ++) {
            [self.dataModel1.data enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                BZCureModel *model = [BZCureModel modelWithDict:obj];
                [pinArr addObject:model];
            }];
        }
        tapVC.listArray = pinArr.copy;
        // 回调的给illLabel赋值的block
        tapVC.dataBlock = ^(NSString *returnString){
            if (returnString.length) {
                self.bingFaLabel.textColor = [UIColor blackColor];
                self.bingFaLabel.text = returnString;
            }
        };
        
        UIBarButtonItem *sureBtn = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:tapVC action:@selector(rightButtonClick)];
        sureBtn.tintColor = [UIColor blackColor];
        UILabel *lb_title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 60)];
        lb_title.text = @"测试cell的复用";
        lb_title.textAlignment = NSTextAlignmentCenter;
        [tapVC.tableView setTableHeaderView:lb_title];
        [tapVC.navigationItem setTitle:@"并发症"];
        [tapVC.navigationItem setRightBarButtonItem:sureBtn];
    }
    else if (tagV == 3){
        
        tapVC.listArray = @[@{@"ci3_name":@"手术治疗"}, @{@"ci3_name":@"药物治疗"}, @{@"ci3_name":@"保守治疗"}];
        
        tapVC.dataBlock = ^(NSString *returnString){
            
            self.cureLabel.textColor = [UIColor blackColor];
            self.cureLabel.text = returnString;
            
        };
        
        [tapVC.navigationItem setTitle:@"治疗方式"];
    }
    [self.navigationController pushViewController:tapVC animated:YES];
}





- (void)cureBtnClick {
    
    FocusDoctorViewController *focus = [[FocusDoctorViewController alloc]init];
    
    [self.navigationController pushViewController:focus animated:YES];
}


@end
